ifeq (${BUILD_OUTPUT_PATH},)
export BUILD_OUTPUT_PATH=$(shell pwd)
endif

CC = gcc
LIB_NAME = libclog

SRC_DIR = src
INC_DIR = include

CFLAGS = -Wall -Wextra -g -fPIC -I$(INC_DIR)
CFLAGS += -DSUBSYS_NAME=$(LIB_NAME)

INC = -I../liblog/include
INC += -I$(BUILD_OUTPUT_PATH)/../include

ifeq ($(TARGET_MODE),debug)
CFLAGS += -DLOG_DEBUG
$(info info : debug mode enabled)
else
$(info info : release mode enabled)
endif

LDFLAGS = -shared -lpthread -lm
LDFLAGS += -lrt

.PHONY: all all_32 clean

SRCS = $(wildcard $(SRC_DIR)/*.c $(SRC_DIR)/utils/*.c)
OBJS = $(patsubst $(SRC_DIR)/%.c, $(BUILD_OUTPUT_PATH)/$(SRC_DIR)/%.o, $(SRCS))
LIB_OBJECT = $(BUILD_OUTPUT_PATH)/$(LIB_NAME).so

all all_32:$(LIB_OBJECT)

$(BUILD_OUTPUT_PATH)/$(SRC_DIR)/%.o: $(SRC_DIR)/%.c
	@mkdir -p $(abspath $(dir $@))
	$(CC) $(CFLAGS) $(INC) -g -o $@ -fpic -c $<

$(LIB_OBJECT): $(OBJS)
	@mkdir -p $(abspath $(dir $@))
	$(CC) $(OBJS) $(LDFLAGS) -o $@

clean:
	rm -rf $(OBJS) $(LIB_OBJECT)